package com.iretailer.report.analyze.device.fieAnalysis;

import com.iretailer.report.analyze.commonUtil.Analyze;
import com.iretailer.report.analyze.commonUtil.ResponeResultType;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory;
import io.netty.handler.codec.http.multipart.HttpDataFactory;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;

import java.util.Map;

/**
 * @Auther: xjw
 * @Date: 2019/3/10 11:11
 * @Description:
 */
public abstract class FileAnalyze implements Analyze {
    private static final HttpDataFactory httpDataFactory =
            new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);

    @Override
    public ResponeResultType nettyAnalyze(Map<String, Object> paramsMap, Object msg) {
        if (msg instanceof HttpRequest) {
            HttpRequest httpRequest = (HttpRequest) msg;
            HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(httpDataFactory, httpRequest);
            return fileInsert(paramsMap, decoder);
        } else {
            return ResponeResultType.getBadRequest(ResponeResultType.CFLType.CLOSE);
        }
    }

    @Override
    public ResponeResultType springAnalyze(Map<String, Object> paramsMap, Object msg) {
        return null;
    }


    public abstract ResponeResultType fileInsert(Map<String, Object> paramsMap, HttpPostRequestDecoder decoder);
}
